//
//  BaseViewController.swift
//  MT
//
//  Created by zhang qiang on 2018/11/21.
//  Copyright © 2018年 张强. All rights reserved.
//

import UIKit
import YPNavigationBarTransition
import MTCategory

open class BaseViewController: UIViewController, RefreshView {
    
    /// 某些特殊情况下使用的导航控制器. 有一定风险, 保证获取的导航控制器上没有 present 出来的控制器, 具体使用结合情况
    lazy var navigationVC: BaseNavController? = {
        return (UIApplication.mt_keyWindow?.rootViewController as? BaseTabBarViewController)?.selectedViewController as? BaseNavController
    }()
    
    lazy var noDataView : NoDataView = {
        return NoDataView.defaultNoDataView()
    }()
    
    func noDataView(hide: Bool) {
        if hide{
            
            noDataView.removeFromSuperview()
            
        }else{
            self.view.addSubview(noDataView)
            noDataView.snp.makeConstraints({ (make) in
                make.edges.equalTo(self.view)
            })
        }
    }
    
    /// 路由初始化参数
    public var rounterParams : Dictionary<String, Any>?
    
    /// Rounter 初始化方法
    required public init(rounterParams params: Dictionary<String, Any>?) {
        self.rounterParams = params
        super.init(nibName: nil, bundle: nil)
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    open func refreshView(){
        
    }
    
    public init(){
        super.init(nibName: nil, bundle: nil)
        self.rounterParams = nil
    }
    
    
    override open func viewDidLoad() {
        super.viewDidLoad()
        extendedLayoutIncludesOpaqueBars = true
        self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.text.x1d1a1a, NSAttributedString.Key.font:PingFangSCSemiboldFont(16)]
        view.backgroundColor = UIColor.theme.background
        // Do any additional setup after loading the view.
    }
    
    override open func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    open override var preferredStatusBarStyle: UIStatusBarStyle {
        return .default
    }
}


extension BaseViewController: NavigationBarConfigureStyle {
    open func yp_navigationBarTintColor() -> UIColor! {
        return UIColor(hex: 0x000000)
    }

    open func yp_navigtionBarConfiguration() -> YPNavigationBarConfigurations {
        return [.backgroundStyleColor, .styleBlack, .backgroundStyleOpaque]
    }
    
    open func yp_navigationBackgroundColor() -> UIColor! {
        return UIColor(hex: 0xFFFFFF)
    }

    open func yp_navigationBackgroundImage(withIdentifier identifier: AutoreleasingUnsafeMutablePointer<NSString?>!) -> UIImage! {
        return nil
    }
}



